package com.dhl.cloud.controller;

import com.dhl.cloud.common.Constants;
import com.dhl.cloud.common.http.HttpResult;
import com.dhl.cloud.course.entity.Summary;
import com.dhl.cloud.course.service.SummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/summary")
public class SummaryController {

    @Autowired
    private SummaryService summaryService;

    @PostMapping("/save")
    public HttpResult saveSummaryService(@RequestBody Summary summary, HttpServletRequest request) {
        Summary entity = summaryService.getSummaryByLession(summary.getLessionid());
        int flag = 0;
        if (entity == null) {
            flag = this.summaryService.saveSummary(summary);
        }
        return flag == 1 ? HttpResult.success("操作成功") : HttpResult.error(Constants.ERROR_MSG_25);
    }

    /**
     * 获取我的课程的notice列表
     */
    @GetMapping("/getSummaryByLession")
    public HttpResult getSummaryByLession(Integer lessionid) {
        Summary summary = summaryService.getSummaryByLession(lessionid);
        return HttpResult.success("", summary);
    }


}
